package com.zhuyp.spring.boot;

public class Threads extends Thread {

	private int num = 0;
	
	private Counter counter;
	
	public Counter getCounter() {
		return counter;
	}

	public void setCounter(Counter counter) {
		this.counter = counter;
	}

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	@Override
	public  void run() {
		StringBuilder str = new StringBuilder(getName()).append(":");
		Integer sum = counter.getSum();
		if (num % 2 == 0) {
			str.append(sum+"+add ").append(num);
			counter.add(num);
		} else {
			counter.minus(num);
			str.append(sum+"-minus").append(num);
		}
		System.out.println(str+",Sum=" + counter.getSum());
	}

}